package com.bstek.uflo.form.service;

import java.util.ArrayList;
import java.util.List;

import com.bstek.dorado.data.provider.Page;
import com.bstek.uflo.command.CommandService;
import com.bstek.uflo.form.command.QueryFormCommand;
import com.bstek.uflo.form.command.QueryTableCommand;
import com.bstek.uflo.form.model.Form;
import com.bstek.uflo.form.model.FormInfo;
import com.bstek.uflo.form.model.TableDefinition;
import com.bstek.uflo.form.model.TableInfo;

/**
 * @author Jacky.gao
 * @since 2013年11月21日
 */
public class FormService {
	private CommandService commandService;
	public static final String BEAN_ID="uflo.form.formService";
	public List<TableInfo> queryTableInfo(){
		Page<TableDefinition> page=new Page<TableDefinition>(10000,1);
		commandService.executeCommand(new QueryTableCommand(page, null));
		List<TableInfo> infos=new ArrayList<TableInfo>();
		for(TableDefinition def:page.getEntities()){
			TableInfo info=new TableInfo();
			info.setDesc(def.getMemo());
			info.setId(def.getId());
			info.setName(def.getName());
			infos.add(info);
		}
		return infos;
	}
	
	public List<FormInfo> queryFormInfos(long tableId){
		List<Form> forms=commandService.executeCommand(new QueryFormCommand(tableId));
		List<FormInfo> infos=new ArrayList<FormInfo>();
		for(Form form:forms){
			FormInfo info=new FormInfo();
			info.setName(form.getName());
			info.setUrl("dorado/uflo/form/dispatch/"+form.getId());
			infos.add(info);
		}
		return infos;
	}

	public CommandService getCommandService() {
		return commandService;
	}

	public void setCommandService(CommandService commandService) {
		this.commandService = commandService;
	}
}
